/*
 * @Author: szx
 * @Date: 2022-03-18 12:46:00
 * @LastEditTime: 2022-03-18 13:09:27
 * @Description:
 * @FilePath: \leetcode\2000-2099\2043\2043.js
 */
/**
 * @param {number[]} balance
 */
var Bank = function (balance) {
    this.balance = balance;
    this.len = balance.length;
};

/**
 * @param {number} account1
 * @param {number} account2
 * @param {number} money
 * @return {boolean}
 */
Bank.prototype.transfer = function (account1, account2, money) {
    if (account1 >= 1 && account1 <= this.len && account2 >= 1 && account2 <= this.len) {
        if (this.withdraw(account1, money)) {
            return this.deposit(account2, money);
        }
    }

    return false;
};

/**
 * @param {number} account
 * @param {number} money
 * @return {boolean}
 */
Bank.prototype.deposit = function (account, money) {
    if (account >= 1 && account <= this.len) {
        this.balance[account - 1] += money;
        return true;
    }
    return false;
};

/**
 * @param {number} account
 * @param {number} money
 * @return {boolean}
 */
Bank.prototype.withdraw = function (account, money) {
    if (account >= 1 && account <= this.len && this.balance[account - 1] >= money) {
        this.balance[account - 1] -= money;
        return true;
    }
    return false;
};

/**
 * Your Bank object will be instantiated and called as such:
 * var obj = new Bank(balance)
 * var param_1 = obj.transfer(account1,account2,money)
 * var param_2 = obj.deposit(account,money)
 * var param_3 = obj.withdraw(account,money)
 */
